package com.mingtu.jgspatrol.activity;

import static com.mingtu.jgspatrol.utils.MyConstant.ItemDecorationSpaces;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import androidx.recyclerview.widget.GridLayoutManager;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.SPStaticUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.blankj.utilcode.util.StringUtils;
import com.mingtu.bio.activity.MyFindActivity;
import com.mingtu.center.activity.AuthSetActivity;
import com.mingtu.center.activity.InfoActivity;
import com.mingtu.center.activity.MyOffLineMapActivity;
import com.mingtu.common.base.BaseBindingActivity;
import com.mingtu.common.utils.ActivityUtil;
import com.mingtu.common.utils.GridSpacingItemDecoration;
import com.mingtu.common.utils.IntentUtils;
import com.mingtu.common.utils.SPTools;
import com.mingtu.common.utils.StatusBarUtil;
import com.mingtu.jgspatrol.R;
import com.mingtu.jgspatrol.adapter.CenterDataAdapter;
import com.mingtu.jgspatrol.databinding.ActivityMineBinding;
import com.mingtu.ocr.activity.MyRecActivity;

public class MineActivity extends BaseBindingActivity<ActivityMineBinding> {
    private String name;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_mine;
    }

    @Override
    protected void initView() {
        hideHeadView();
        int statusBarHeight = StatusBarUtil.getStatusBarHeight(context);
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) binding.layoutTitle.getLayoutParams();
        lp.setMargins(0, statusBarHeight, 0, 0);
        binding.layoutTitle.setLayoutParams(lp);


        CenterDataAdapter centerDataAdapter = new CenterDataAdapter(context);
        GridLayoutManager layoutManager = new GridLayoutManager(context, 3);//第二个参数为网格的列数
        binding.recycler.addItemDecoration(new GridSpacingItemDecoration(3, SizeUtils.dp2px(ItemDecorationSpaces), true));
//        recycler.setHasFixedSize(true);
        binding.recycler.setLayoutManager(layoutManager);
        binding.recycler.setAdapter(centerDataAdapter);
        centerDataAdapter.setOnItemClickListener(new CenterDataAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                Bundle bundle = new Bundle();
                switch (position) {
                    case 0:
                        //巡护记录
                        bundle.putInt("navPositon", 0);
                        IntentUtils.getInstance().readyGo(ActivityUtils.getTopActivity(), MyRecordActivity.class, bundle);
                        break;
                    case 1:
                        //离线地图
                        IntentUtils.getInstance().readyGo(ActivityUtils.getTopActivity(), MyOffLineMapActivity.class);
                        break;
                    case 2:
                        //权限设置
                        IntentUtils.getInstance().readyGo(ActivityUtils.getTopActivity(), AuthSetActivity.class);
                        break;
                    case 3:
                        //我的发现
                        IntentUtils.getInstance().readyGo(ActivityUtils.getTopActivity(), MyFindActivity.class);
                        break;
                    case 4:
                        //识别馆
                        IntentUtils.getInstance().readyGo(ActivityUtils.getTopActivity(), MyRecActivity.class);
                        break;

//                    case 5:
//                        //720全景
//                        bundle.putString("title", "720全景");
//                        bundle.putString("url", MyConstant.URL_720);
//                        IntentUtils.getInstance().readyGo(ActivityUtils.getTopActivity(), TbsWebActivity.class, bundle);
//                        break;
//                    case 5:
//                        //视频会议
//                        IntentUtils.getInstance().readyGo(getActivity(), MeetingActivity.class);
//                        break;
//                    case 7:
//                        //我的签到
//                        bundle.putInt("navPositon", 2);
//                        IntentUtils.getInstance().readyGo(getActivity(), MyRecordActivity.class, bundle);
//                        break;
                }

            }
        });
    }

    @Override
    protected void initData() {
        name = SPStaticUtils.getString(SPTools.userName);
        if (!StringUtils.isEmpty(name)) {
            binding.tvName.setText(name);
        }

        addClickListener(this,binding.ivBack,binding.ivHead,binding.tvAccountSet);
    }

    @Override
    protected void getData() {

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.iv_back:
                ActivityUtil.removeActivity(this);
                break;
            case R.id.iv_head:
                //用户信息
                String mobile = SPStaticUtils.getString(SPTools.mobile);//联系方式
                String roleName = SPStaticUtils.getString(SPTools.roleName);
                String deptName = SPStaticUtils.getString(SPTools.deptName);

                Bundle bundle = new Bundle();
                bundle.putString("name", name);
                bundle.putString("mobile", mobile);
                bundle.putString("roleName", roleName);
                bundle.putString("deptName", deptName);
                IntentUtils.getInstance().readyGo(ActivityUtils.getTopActivity(), InfoActivity.class, bundle);
                break;
            case R.id.tv_account_set:
                //账号设置
                IntentUtils.getInstance().readyGo(ActivityUtils.getTopActivity(), MySetActivity.class);
                break;
        }
    }
}